requireJS(['constant', 'site', 'handlebars'], function (constant, site, Handlebars) {

    var updataSmsData = {};//修改id
    function MessagesFun() {
        // 短信接口
        site.send({
            url: 'manager/selectMessages.do',
            //async:false
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type == '1') {
                    $("#mUsername").val(list.content.username)
                    $("#mPassword").val(list.content.password)
                    updataSmsData.id = list.content.id;
                } else {
                    constant.fn.Message('F', list.msg);
                }


            }
        })
    }

    MessagesFun();

    $(".submit-message").on('click', function () {
        updataSmsData.username = $("#mUsername").val()
        updataSmsData.password = $("#mPassword").val()
        site.send({
            url: 'manager/updateMessages.do',
            //async:false,
            data:updataSmsData,
            callback: function (data) {
                var list = JSON.parse(data);
                if (list.type == '1') {
                    constant.fn.Message('T', list.msg);

                } else {
                    constant.fn.Message('F', list.msg);
                }


            }
        })
    })
    $("#testSendSms").on('click', function () {
        var phone = $('.phone').val();
        var username = $("#mUsername").val()
        var password = $("#mPassword").val()
        if (!username) {
            constant.fn.Message('I', '请输入用户名');
            return
        }
        if (!password) {
            constant.fn.Message('I', '请输入密码');
            return
        }
        if (!phone) {
            constant.fn.Message('I', '请输入手机号码');
            return
        }
        if (!constant.reg.phone.test(phone)) {
            constant.fn.Message('I', '手机号码格式有误')
            return
        }

        site.send({
            url: 'manager/testSendMessage.do',
            data: {
                phones:phone,
                username:username,
                password:password
            },
            callback:function(data){
                data = JSON.parse(data);
                if(data.type == 1){
                    constant.fn.Message("T",data.msg);
                }
                else{
                    constant.fn.Message("F",data.msg);
                }
            }
        })
    })
})